/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package interface_graphique;

import ClassesJava.Salle;
import static interface_graphique.MenuPrincipale.menu;
import java.awt.Component;
import java.util.*;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Mariam
 */
public class Les_Salles extends javax.swing.JFrame {

    /**
     * Creates new form Les_Salles
     */
    Salle lists;
    DefaultTableModel model = new DefaultTableModel();
    int ids, j;

    public Les_Salles() {
        initComponents();
          setLocationRelativeTo(null);

        model.addColumn("Numéro");
        model.addColumn("Type");
        model.addColumn("Bloc");
        model.addColumn("Nb_places");
        tabLes_Salles.setModel(model);
        lists = new Salle();
        afficher();
        afficher(0);
    }

    public void afficher() {
        model.setRowCount(0);
        Vector<Salle> res = new Vector();
        res = lists.getSalle();
        for (int i = 0; i < res.size(); i++) {
            Object[] e = {res.get(i).getNum(), res.get(i).gettype(), res.get(i).getbloc(), res.get(i).getNbplace()};
            model.addRow(e);
        }
    }

    // afficher un filiere i dans les texte 

    private void afficher(int i) {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        ids = (int) model.getValueAt(i, 0);
        txtnum.setText(model.getValueAt(i, 0).toString());
        txttype.setText(model.getValueAt(i, 1).toString());
        txtbloc.setText(model.getValueAt(i, 2).toString());
        txtNbplace.setText(model.getValueAt(i, 3).toString());
    }


    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton5 = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        txtbloc = new javax.swing.JTextField();
        txttype = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        tabLes_Salles = new javax.swing.JTable();
        jLabel5 = new javax.swing.JLabel();
        Ajouter = new javax.swing.JButton();
        modifier = new javax.swing.JButton();
        supprimer = new javax.swing.JButton();
        dernierElement = new javax.swing.JButton();
        president = new javax.swing.JButton();
        suivant = new javax.swing.JButton();
        premierElement = new javax.swing.JButton();
        Enregistrer = new javax.swing.JButton();
        jLabel7 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        txtnum = new javax.swing.JTextField();
        txtNbplace = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();

        jButton5.setText("jButton5");

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setUndecorated(true);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
        });

        jPanel2.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel3.setFont(new java.awt.Font("Comic Sans MS", 1, 14)); // NOI18N
        jLabel3.setForeground(new java.awt.Color(255, 255, 255));
        jLabel3.setText("Nomber des places");
        jPanel2.add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 120, 130, 30));

        jLabel1.setFont(new java.awt.Font("Comic Sans MS", 1, 14)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(255, 255, 255));
        jLabel1.setText("Bloc");
        jPanel2.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 160, 50, 20));

        jLabel4.setFont(new java.awt.Font("Comic Sans MS", 1, 14)); // NOI18N
        jLabel4.setForeground(new java.awt.Color(255, 255, 255));
        jLabel4.setText("Type");
        jPanel2.add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 200, 60, 20));

        txtbloc.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtblocActionPerformed(evt);
            }
        });
        jPanel2.add(txtbloc, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 160, 200, 30));
        jPanel2.add(txttype, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 200, 200, 30));

        tabLes_Salles.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null}
            },
            new String [] {
                "Numero", "Bloc", "Type"
            }
        ));
        tabLes_Salles.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tabLes_SallesMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tabLes_Salles);

        jPanel2.add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 280, 460, 150));

        jLabel5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/lllllllllllllll.png"))); // NOI18N
        jLabel5.setText("jLabel5");
        jPanel2.add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(480, 330, 90, 80));

        Ajouter.setBackground(new java.awt.Color(51, 102, 255));
        Ajouter.setFont(new java.awt.Font("Comic Sans MS", 0, 12)); // NOI18N
        Ajouter.setForeground(new java.awt.Color(255, 255, 255));
        Ajouter.setText("Ajouter");
        Ajouter.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AjouterActionPerformed(evt);
            }
        });
        jPanel2.add(Ajouter, new org.netbeans.lib.awtextra.AbsoluteConstraints(380, 80, 100, -1));

        modifier.setBackground(new java.awt.Color(51, 51, 255));
        modifier.setFont(new java.awt.Font("Comic Sans MS", 0, 12)); // NOI18N
        modifier.setForeground(new java.awt.Color(255, 255, 255));
        modifier.setText("Modifier");
        modifier.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                modifierActionPerformed(evt);
            }
        });
        jPanel2.add(modifier, new org.netbeans.lib.awtextra.AbsoluteConstraints(380, 120, 100, 30));

        supprimer.setBackground(new java.awt.Color(51, 102, 255));
        supprimer.setFont(new java.awt.Font("Comic Sans MS", 0, 12)); // NOI18N
        supprimer.setForeground(new java.awt.Color(255, 255, 255));
        supprimer.setText("Supprimer");
        supprimer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                supprimerActionPerformed(evt);
            }
        });
        jPanel2.add(supprimer, new org.netbeans.lib.awtextra.AbsoluteConstraints(380, 160, 100, -1));

        dernierElement.setBackground(new java.awt.Color(51, 51, 255));
        dernierElement.setFont(new java.awt.Font("Comic Sans MS", 0, 12)); // NOI18N
        dernierElement.setForeground(new java.awt.Color(255, 255, 255));
        dernierElement.setText(">>");
        dernierElement.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                dernierElementActionPerformed(evt);
            }
        });
        jPanel2.add(dernierElement, new org.netbeans.lib.awtextra.AbsoluteConstraints(420, 240, 60, -1));

        president.setBackground(new java.awt.Color(51, 51, 255));
        president.setFont(new java.awt.Font("Comic Sans MS", 0, 12)); // NOI18N
        president.setForeground(new java.awt.Color(255, 255, 255));
        president.setText("<");
        president.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                presidentActionPerformed(evt);
            }
        });
        jPanel2.add(president, new org.netbeans.lib.awtextra.AbsoluteConstraints(260, 240, 60, -1));

        suivant.setBackground(new java.awt.Color(51, 51, 255));
        suivant.setFont(new java.awt.Font("Comic Sans MS", 0, 12)); // NOI18N
        suivant.setForeground(new java.awt.Color(255, 255, 255));
        suivant.setText(">");
        suivant.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                suivantActionPerformed(evt);
            }
        });
        jPanel2.add(suivant, new org.netbeans.lib.awtextra.AbsoluteConstraints(340, 240, 60, -1));

        premierElement.setBackground(new java.awt.Color(51, 51, 255));
        premierElement.setFont(new java.awt.Font("Comic Sans MS", 0, 12)); // NOI18N
        premierElement.setForeground(new java.awt.Color(255, 255, 255));
        premierElement.setText("<<");
        premierElement.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                premierElementActionPerformed(evt);
            }
        });
        jPanel2.add(premierElement, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 240, 60, -1));

        Enregistrer.setBackground(new java.awt.Color(51, 51, 255));
        Enregistrer.setFont(new java.awt.Font("Comic Sans MS", 0, 12)); // NOI18N
        Enregistrer.setForeground(new java.awt.Color(255, 255, 255));
        Enregistrer.setText("Enregistrer");
        Enregistrer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                EnregistrerActionPerformed(evt);
            }
        });
        jPanel2.add(Enregistrer, new org.netbeans.lib.awtextra.AbsoluteConstraints(380, 200, -1, -1));

        jLabel7.setFont(new java.awt.Font("Comic Sans MS", 1, 14)); // NOI18N
        jLabel7.setForeground(new java.awt.Color(255, 255, 255));
        jLabel7.setText("Numero");
        jPanel2.add(jLabel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 80, 90, 30));

        jLabel6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/gSalles.png"))); // NOI18N
        jPanel2.add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 10, 450, 70));

        txtnum.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtnumActionPerformed(evt);
            }
        });
        jPanel2.add(txtnum, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 80, 200, 30));

        txtNbplace.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtNbplaceActionPerformed(evt);
            }
        });
        jPanel2.add(txtNbplace, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 120, 200, 30));

        jLabel8.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/redoit.png"))); // NOI18N
        jLabel8.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jLabel8.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel8MouseClicked(evt);
            }
        });
        jPanel2.add(jLabel8, new org.netbeans.lib.awtextra.AbsoluteConstraints(510, 0, -1, -1));

        jLabel9.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/quite.png"))); // NOI18N
        jLabel9.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jLabel9.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel9MouseClicked(evt);
            }
        });
        jPanel2.add(jLabel9, new org.netbeans.lib.awtextra.AbsoluteConstraints(550, 0, -1, -1));

        jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/ar.png"))); // NOI18N
        jPanel2.add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 590, 430));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void txtblocActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtblocActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtblocActionPerformed

    private void AjouterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AjouterActionPerformed
        // ajouter
          txtbloc.setText("");
        txttype.setText("");
        txtNbplace.setText("");
       
    }//GEN-LAST:event_AjouterActionPerformed

    private void dernierElementActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dernierElementActionPerformed
        //>>
        j = tabLes_Salles.getRowCount() - 1;
        afficher(j);
    }//GEN-LAST:event_dernierElementActionPerformed

    private void supprimerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_supprimerActionPerformed
        //botton supprimer 
        int i;
        Salle s;
         s = new Salle(Integer.parseInt(txtnum.getText()),Integer.parseInt(txtNbplace.getText()), txttype.getText(), txtbloc.getText());
        i = s.supprimerSal(s);
        if (i == 1) {
            afficher();
            javax.swing.JOptionPane.showMessageDialog(null, "Une salle est bien Supprimer", "Supprimer Une salle ", javax.swing.JOptionPane.INFORMATION_MESSAGE);
        } else {
            javax.swing.JOptionPane.showMessageDialog(null, "echec de supprimer salle", "Supprimer une salle", javax.swing.JOptionPane.INFORMATION_MESSAGE);
        }

    }//GEN-LAST:event_supprimerActionPerformed

    private void modifierActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_modifierActionPerformed
        //modifier  
        int i;
        Salle s;
        s = new Salle(Integer.parseInt(txtnum.getText()),Integer.parseInt(txtNbplace.getText()), txttype.getText(), txtbloc.getText());
         i = s.modifierSal(s);
        if (i == 1) {
            afficher();
            javax.swing.JOptionPane.showMessageDialog(null, "La salle est bien Modifier", "Modifier une salle", javax.swing.JOptionPane.INFORMATION_MESSAGE);
        } else {
            javax.swing.JOptionPane.showMessageDialog(null, "echec de Modifier La salle", "Modifier ne salle", javax.swing.JOptionPane.INFORMATION_MESSAGE);
        }
    }//GEN-LAST:event_modifierActionPerformed

    private void EnregistrerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_EnregistrerActionPerformed
        // Enregistrer
         int i;
        Salle s;
        s = new Salle(Integer.parseInt(txtnum.getText()),Integer.parseInt(txtNbplace.getText()), txttype.getText(), txtbloc.getText());
        i = s.ajoutersSal(s);
        if (i == 1) {
            afficher();
            javax.swing.JOptionPane.showMessageDialog(null, "Une nouveau salle est bien enregistré", "Ajouter un salle", javax.swing.JOptionPane.INFORMATION_MESSAGE);
        } else {
            javax.swing.JOptionPane.showMessageDialog(null, "echec d'ajouter nouveau salle", "Ajouter un salle", javax.swing.JOptionPane.INFORMATION_MESSAGE);
        }
      
    }//GEN-LAST:event_EnregistrerActionPerformed

    private void premierElementActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_premierElementActionPerformed
        // <<
        j = 0;
        afficher(j);
    }//GEN-LAST:event_premierElementActionPerformed

    private void presidentActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_presidentActionPerformed
        // <
        if (j > 0) {
            j--;
            afficher(j);
        }
    }//GEN-LAST:event_presidentActionPerformed

    private void suivantActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_suivantActionPerformed
        // >
        if (j < tabLes_Salles.getRowCount() - 1) {
            j++;
            afficher(j);
        }
    }//GEN-LAST:event_suivantActionPerformed

    private void txtnumActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtnumActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtnumActionPerformed

    private void txtNbplaceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtNbplaceActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtNbplaceActionPerformed

    private void tabLes_SallesMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tabLes_SallesMouseClicked
        j = tabLes_Salles.getSelectedRow();
        afficher(j);
    }//GEN-LAST:event_tabLes_SallesMouseClicked

    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
        menu.setVisible(true);
    }//GEN-LAST:event_formWindowClosed

    private void jLabel8MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel8MouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_jLabel8MouseClicked

    private void jLabel9MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel9MouseClicked
        menu.setVisible(true);
        this.setVisible(false);

    }//GEN-LAST:event_jLabel9MouseClicked

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Les_Salles.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Les_Salles.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Les_Salles.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Les_Salles.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Les_Salles().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton Ajouter;
    private javax.swing.JButton Enregistrer;
    private javax.swing.JButton dernierElement;
    private javax.swing.JButton jButton5;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton modifier;
    private javax.swing.JButton premierElement;
    private javax.swing.JButton president;
    private javax.swing.JButton suivant;
    private javax.swing.JButton supprimer;
    private javax.swing.JTable tabLes_Salles;
    private javax.swing.JTextField txtNbplace;
    private javax.swing.JTextField txtbloc;
    private javax.swing.JTextField txtnum;
    private javax.swing.JTextField txttype;
    // End of variables declaration//GEN-END:variables
}
